package com.example.administrator.myapplication;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    Button mBtnOk;
    SeekBar mSeekBar;
    TextView mTv2,mTvShow;
  EditText mEtName;
 CheckBox mCBsour,mCbLa,mCbSu,mCbHun;
    int id;
    ImageView mIvShow;
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTv2=findViewById(R.id.tv2);
        mSeekBar=findViewById(R.id.progress);
        mEtName=findViewById(R.id.et_name);
        mCBsour=findViewById(R.id.suar);
        mCbHun=findViewById(R.id.hun);
        mCbLa=findViewById(R.id.la);
        mCbSu=findViewById(R.id.su);
        mBtnOk=findViewById(R.id.bt_ok);
        mTvShow=findViewById(R.id.tv_show);
        mIvShow=findViewById(R.id.iv_show);
        //获取意图对象
        Intent intent=getIntent();
       Bundle bundle=intent.getExtras();
      String username=bundle.getString("username");
        //显示数据
        mEtName.setText(username);
/*mCBsour.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        boolean issour = mCBsour.isChecked();

        Log.e(TAG, "onCheckedChanged: "+(issour?"酸":""));
    }
});*/

mSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override

    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            mTv2.setText( Integer.toString(i)+" 元" );
             id = Integer.parseInt(String.valueOf(i));

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        Log.e("------------", "onStartTrackingTouch: 开始滑动" );
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        Log.e("------------", "onStopTrackingTouch: 停止滑动" );
    }
});

mBtnOk.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        boolean la=mCbLa.isChecked();
        boolean  su= mCbSu.isChecked();
        boolean  hun=mCbHun.isChecked();
        boolean  sua=mCBsour.isChecked();
        String pric= mTv2.getText().toString();

//                int id;
//                id= Integer.parseInt( pric);
        Log.e(TAG, "onClick: "+pric );
        if((sua && la && su)){
            if( id<=45){
                //桂林米粉
                mTvShow.setText("酸煮鱼");

                mIvShow.setImageResource(R.mipmap.shuizhuyu);
            }
        }else {

        }
        if((la && hun)){
            if( id<=80){
                //麻辣火锅
               mTvShow.setText("麻辣火锅");
                mIvShow.setImageResource(R.mipmap.malahuoguo);
            }
        }
        if(sua &&hun){
            if(id<=35){
                //酸菜牛肉面
               mTvShow.setText("酸菜牛肉面");
                mIvShow.setImageResource(R.mipmap.suncainiuroumian);
            }
        }
        if(su){
            if(id<=38){
                //西芹炒百合
                mTvShow.setText("西芹炒百合");
                mIvShow.setImageResource(R.mipmap.xiqin);
            }
        }
        if(hun){
            if (id<=60){
                //红烧肉
                mTvShow.setText("红烧肉");
               mIvShow.setImageResource(R.mipmap.hongshaorou);
            }
        }

    }

});



    }


     /* mBtnFnext=findViewById(R.id.bt_fnext);

        mBtnFnext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //神奇的跳转意图
                Intent intent =new Intent(MainActivity.this,MyActivity.class);
                //
                startActivity(intent);
            }
        });*/
    }


